﻿using Newtonsoft.Json.Linq;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace thousandClear.Util.SMS
{
    public static class CorpSmsClient
    {
        public static void SendSms(string accessToken, string toUser, string msg)
        {
            var client = new RestClient("https://qyapi.weixin.qq.com/cgi-bin");

            var request = new RestRequest("message/send?access_token={access_token}", Method.POST);
            request.AddUrlSegment("access_token", accessToken);

            var post = new
            {
                touser = toUser,
                toparty = "",
                totag = "",
                msgtype = "text",
                agentid = "2",
                text = new
                {
                    content = msg,
                },
                safe = 0,
            };

            request.RequestFormat = DataFormat.Json;
            request.AddJsonBody(post);

            var result = JObject.Parse(client.Execute(request).Content);
        }
    }
}
